<div class="row content-nav">
    <div class="col-xs-12">
        <ul>
            <li><a href="javascript:;"><i></i>&nbsp;盈利管理</a></li>
            <li><a href="javascript:;">月度统计</a></li>
        </ul>
    </div>
</div>

<div class="layui-fluid" id="search-box">
    <div class="layui-card">
        <div class="layui-card-body">
            <form class="layui-form layui-form-pane" action="">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">统计月份：</label>
                        <div class="layui-input-inline" style="width:300px;">
                            <input type="text" class="layui-input" id="month" name="month" placeholder=" - ">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button type="button" id="search-btn" class="layui-btn layui-btn-sm layui-bg-light-blue"><i class="layui-icon layui-icon-search"></i> 搜索</button>
                    </div>
                </div>

            </form>
        </div>
    </div>
</div>

<section class="content clearfix">
    <div class="layui-list-box">
        <table class="layui-hide" id="list-box" lay-filter="list-box"></table>
    </div>
</section>

<script type="text/html" id="list-toolbar">
    <div class="layui-btn-container">
        <button lay-event="refresh" type="button" class="layui-btn layui-btn-sm layui-bg-red"><i class="layui-icon">&#xe9aa;</i> 刷新</button>
    </div>
</script>

<script>
    layui.use(['table','form','laydate'], function () {
        var table = layui.table;
        var form = layui.form;
        var laydate = layui.laydate;
        laydate.render({
            elem: '#month'
            ,type: 'month'
         //   ,range: '~'
        });


        table.render({
            elem: '#list-box'
            , url: '{:createUrl("monthlyStatistics")}'
            , toolbar: '#list-toolbar'
            , defaultToolbar: []
            , title: '数据表'
            , cols: [[
                {type: 'checkbox'}
                , {field: 'date', title: '日期',width:120,align:'center'}
                , {field: 'user_id', title: '用户ID',width:100,align:'left'}
                , {field: 'username', title: '用户名',width:130,align:'left'}
                , {field: '', title: '盈利',align:"center",minWidth:110,templet: function(res){
                        if(typeof(res.profit) == 'object') {
                            return 0;
                        }
                        return floorScale(res.profit,4);
                    }}
                , {field: '', title: '成本',align:"center",minWidth:110,templet: function(res){
                        if(typeof(res.cost) == 'object') {
                            return 0;
                        }
                        return floorScale(res.cost,4);
                    }}
                , {field: '', title: '卖出',align:"center",minWidth:110,templet: function(res){
                        if(typeof(res.sell) == 'object') {
                            return 0;
                        }
                        return floorScale(res.sell,4);
                    }}
                , {field: '', title: '保留',align:"center",minWidth:110,templet: function(res){
                        if(typeof(res.reserved) == 'object') {
                            return 0;
                        }
                        return floorScale(res.reserved,4);
                    }}
                , {field: '', title: '手续费',align:"center",minWidth:110,templet: function(res){
                        if(typeof(res.field_fees) == 'object') {
                            return 0;
                        }
                        return floorScale(res.field_fees,4);
                    }}
                , {field: '', title: '节省手续费',align:"center",minWidth:110,templet: function(res){
                        if(typeof(res.reduce_fees) == 'object') {
                            return 0;
                        }
                        return floorScale(res.reduce_fees,4);
                    }}
                , {field: '', title: '已收服务费',align:"center",minWidth:110,templet: function(res){
                        if(typeof(res.service_charge_deducted) == 'object') {
                            return 0;
                        }
                        return floorScale(res.service_charge_deducted,4);
                    }}

            ]]
            , page: true
            , id: 'list-table'
            , height: 'full-310'
             ,limit:50
        });

        $("#search-btn").on("click",function (){
            table.reload('list-table', {
             /*   page: {
                    curr: 1
                }
                ,*/where: {
                    key: {
                        month : $('[name="month"]').val(),
                    }
                }
            }, 'data');
        });

        //头工具栏事件
        table.on('toolbar(list-box)', function (obj) {
            switch (obj.event) {
                case 'url':
                    window.location.href = "{:createUrl('editor')}";
                    break;
                case 'refresh':
                    window.location.reload();
                    break;
            }
        });

        //监听行工具事件
        table.on('tool(list-box)', function (obj) {
            var data = obj.data;
            if (obj.event === 'del') {
                layer.confirm('你确定要删除吗？', function (index) {
                    $.get('{:createUrl("delete")}',{
                        id : data.id
                    },function(result){
                        layer.close(index);
                        if(result.code){
                            obj.del();
                        }else{
                            layer.msg(result.msg,{ icon : 2 });
                        }
                    },"json");
                });
            } else if (obj.event === 'edit') {
                window.location.href = '{:createUrl("detail")}?id='+data.id;
            }else if(obj.event == 'judge'){
                layer.open({
                    type: 2,
                    title: '判罚',
                    shadeClose: true,
                    shade: 0.3,
                    area: ['25%', '48%'],
                    content: '{:createUrl("judge")}?id='+data.id
                });
            }else if(obj.event == 'logistics'){
                layer.open({
                    type: 2,
                    title: '物流查询',
                    shadeClose: true,
                    shade: 0.3,
                    area: ['60%', '58%'],
                    content: '{:createUrl("express")}?id='+data.id
                });
            }
        });

    });

    function showBig(src) {
        layer.photos({
            photos: {"data": [{"src":src}]},
            anim: 0
        });
    }
</script>